import 'package:flutter/animation.dart';
import 'package:flutter/material.dart';
import 'package:iidx_progress_tool/components/detail/music_data_detail.dart';
import 'package:iidx_progress_tool/data/model/music_data.dart';

class MusicListItem extends StatelessWidget {
  final MusicData musicData;

  const MusicListItem({
    super.key,
    required this.musicData
  });

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text(
        musicData.title,
        style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
      ),
      subtitle: Text(musicData.artist),
      titleAlignment: ListTileTitleAlignment.top,
      onTap: () {
        Navigator.of(context).push(_createDataDetailRoute(this.musicData));
      },
    );
  }

  Route _createDataDetailRoute(MusicData musicData) {
    return PageRouteBuilder(
      pageBuilder: (context, animation, secondaryAnimation) => MusicDataDetail(musicData: musicData),
      transitionsBuilder: (context, animation, secondaryAnimation, child) {
        const begin = Offset(1.0, 0.0);
        const end = Offset.zero;
        var curve = Curves.ease;
        final tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
        final offsetAnimation = animation.drive(tween);
        return SlideTransition(
          position: offsetAnimation,
          child: child,
        );
      }
    );
  }
}